<%@ include file="/en/jsp/static.jsp" %>
<%@ page import="linuxbox.bbs.logic.*" %>
<%@ page import="java.util.*" %>
<%@ page import="linuxbox.bbs.bean.BbsMsgKey" %>

<%@ taglib uri="/linuxbox/bbs.tld" prefix="bbs" %>

<%
  String sQuery = request.getParameter("QUERY_TEXT");
  if (sQuery == null)
    sQuery = "";

  String sQuerySubject = request.getParameter("SUBJECT");
  int iQuerySubject = 0;
  if (sQuerySubject != null && !sQuerySubject.equals(""))
    iQuerySubject = 1;

  String sQueryContent = request.getParameter("CONTENT");
  int iQueryContent = 0;
  if (sQueryContent != null && !sQueryContent.equals(""))
    iQueryContent = 10;

  String sQueryAuthor = request.getParameter("AUTHOR");
  int iQueryAuthor = 0;
  if (sQueryAuthor != null && !sQueryAuthor.equals(""))
    iQueryAuthor = 100;

  int iType = iQuerySubject + iQueryContent + iQueryAuthor;

  BbsManager bm = BbsManager.getInstance();
%>

<jsp:include page="/en/jsp/header.jsp" flush="true"/>


<SCRIPT LANGUAGE="Javascript">
function onChangeCategory()
{
    document.theForm.submit();
}
</SCRIPT>

<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
  <tr>
    <td>
      &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
      <b><%=boxName%> - BBS Search</b>
    </td>
<FORM action="<%=BoxStatic.servletDir%>BbsContentAction" method="POST" name="theForm" >
    <td ALIGN="right" valign="top">
      <a href="<%=BoxStatic.jspDir%>bbs/BbsNewList.jsp">New List</a>&nbsp;|&nbsp;

      <a href="<%=BoxStatic.jspDir%>bbs/BbsQueryAll.jsp">Search</a>

      &nbsp;|&nbsp;View Category
        <SELECT NAME="CAT_ID" onclick="onChangeCategory()">
          <bbs:BbsCatList listType="list"/>
        </select>
    </td>
</form>
  </tr>
</table>

<hr width="100%" color=#E06000 align=left>

<table width="100%" border=0 cellpadding=0 cellspacing=0>
  <tr><td>
    <table width="98%" border=0 bgcolor="#f0f0f0" style="font-size:14px">
      <form action="<%=BoxStatic.jspDir%>bbs/BbsQueryAll.jsp" method=post name=search>
      <tr>
        <td align=left>Search:
          <input type="text" size="20" name="QUERY_TEXT" value="<%=sQuery%>">
          <input type="submit" name="OK" value="Search">
        </td>
      </tr>

      <tr>
        <td align=left>Choose searching category:
          <input type="checkbox" Name="SUBJECT" Value=1
            <% if ( iQuerySubject == 1)
                out.print(" checked ");
            %>>By subject
          <input type="checkbox" Name="CONTENT" Value=10
            <% if ( iQueryContent == 10)
                out.print(" checked ");
            %>>By content
          <input type="checkbox" Name="AUTHOR" Value=100
            <% if ( iQueryAuthor == 100)
                out.print(" checked ");
            %>>By Author
        </td>
      </tr>
      </form>
    </table>
  </td></tr>
  <tr><td>

<%
  int length = 0;
  if (iType != 0 && !sQuery.equals("")) {
    BbsMsgKey key = null;
    BbsMsg msg = null;

    try
    {
      ArrayList keys = bm.queryByType(0, iType, sQuery);
      length = keys.size();
      if (length>0)
      {
%>
    <TABLE cellSpacing=1 cellPadding=0 width="100%" border=0 bgColor=#dddddd>
      <tr bgcolor=#7EC1F3>
        <td><b>Time</b></td>
        <td><b>Author</b></td>
        <td><b>Category</b></td>
        <td><b>Subject</b></td>
      </tr>

<%
      for (int i = 0; i < length; i++)
      {
        key = (BbsMsgKey)keys.get(i);
        msg = bm.getBbsMsg(key);

        long lMsgID = msg.getID();
        String sAuthor = msg.getAuthor();
        java.sql.Date dtSubDate = msg.getSubDate();
        java.sql.Time tmSubTime = msg.getSubTime();
        String sSubject = msg.getSubject();
        String sCatName = msg.getCatName();
        int iCatID = msg.getCategory();

        String proptime = dtSubDate.toString() + " " + tmSubTime.toString();
        if (sSubject == null || sSubject.equals(""))
           sSubject = "(No subject)";
%>

      <tr <% if ((i % 2) == 0) out.print("bgcolor=#f0f0f0"); %>>
        <td><%=proptime%></td>
        <td><%=sAuthor%></td>
        <td><%=sCatName%></td>
        <td>
          <a href="<%=BoxStatic.servletDir%>BbsViewAction?CAT_ID=<%=iCatID%>&MSG_ID=<%=lMsgID%>"><%=sSubject%></a>
        </td>
      </tr>

<%
      } //for
%>
    </table>
        There are total <%=length%> messages found.
<%
      } //if
      else
      {
        out.print("No messages found!");
      }
    }
    catch(Exception e)
    {
      System.out.println("Error : " + e.getMessage());
    }
  }
%>
  </td></tr>
</table>


<hr width="100%" color=#E06000 align=left>

<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
